<?php

/*
Zoo Management Simulation
This is the Admin UI. It provides an overview of the cages and provides the user with adding, editing, deleting and securing doors options,
which are sent to the adminCageProcess file
The UI can also allow the user to call security which presents a small message box notifying them that security has been called
*/

include("dbconnect.php");
$sql = 'SELECT * FROM enclosure';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zoo Management Administator Page</title>
<link href="mainstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<h1>Zoo Management Administator Page</h1>
<div align="center">
<?php
  echo "<form id='adminCageForm' name='adminCageForm' method='post' enctype='multipart/form-data' action='adminCageProcess.php'>";
  echo "<input type='submit' name='submit' id='submit' value='Lock all doors' />";
  echo "</form>";
?>
</div>

<table id="zootable" width="100%" border="1">
  <tr>
    <td id="tableheader">Name</td>
    <td id="tableheader">Enclosure Number</td>
    <td id="tableheader">Size</td>
    <td id="tableheader">Type</td>
    <td id="tableheader">Number of entries</td>
    <td id="tableheader">Exhibit Name</td>
    <td id="tableheader">Exhibit Description</td>
    <td id="tableheader">Lock Status</td>
    <td id="tableheader">Light Status</td>
    <td id="tableheader">Human Detector</td>
    <td id="tableheader">Animal Detector</td>
  </tr>
  
 <?php
  $cagenumber = 1;
		foreach ($dbh->query($sql) as $row)
		{
			echo "<form id='CageForm' name='CageForm' method='post' enctype='multipart/form-data' action='setupAdminProcess.php?id=".$row[0]."'>";
			echo "<tr>";
			echo "<td>" . "<a href='cage.php?cageid=".$row[0]."&cagenumber=". $cagenumber."' title='".$row[1]."'>". $row[1]. "</a></td>";
			echo "<td>". $cagenumber . "</td>";
			echo "<td>". $row[2]. "m2</td>";

			echo "<td>";
			$typesql = "SELECT enclosureTypeDesc FROM enclosureType WHERE enclosureTypeId='". $row[3] . "'";
			foreach ($dbh->query($typesql) as $typerow)
			{
				echo $typerow[0];
			}
			echo "</td>";
			echo "<td>". $row[6] . "</td>";
			echo "<td>". $row[4]. "</td>";
			echo "<td>". $row[5]. "</td>";
			echo "<td>";
			if ($row[8] == 0){
			echo "Unlocked";}
			else {
			echo "Locked";}
			echo "</td>";
			echo "<td>";
			if ($row[7] == 0){
			echo "Off";}
			elseif ($row[7] == 1){
			echo "On";}
			echo "</td>";
			if ($row[10] == 1){
			echo "<td>Human Inside</td>";
			}
			else{echo "<td>No Human Inside</td>";}
			if ($row[9] == 1){
			echo "<td>Animal Inside</td>";
			}
			else{echo "<td>No Animal Inside</td>";}
			
			echo "<td>". "<input type='submit' name='submit' id='submit' value='Edit' />" . "</td>";
			echo "<td>". "<input type='submit' name='submit' id='submit' value='Delete' />" . "</td>";
			echo "</tr>";
			echo "</form>";
			$cagenumber+=1;
		}
	$dbh = null;
	?>        
        
</table>
<div align="center">
<form id='adminCageForm' name='adminCageForm' method='post' enctype='multipart/form-data' action='setupAdminProcess.php'>
<input type='submit' name='submit' id='submit' value='Add cage' />
<input type='submit' name='submit' id='submit' value='Return to Zoo page' />
</form></div>

</body>
</html>